package com.mt.api.modules.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mt.api.core.page.PageFactory;
import com.mt.api.modules.domain.Instore;
import com.mt.api.modules.domain.bo.AppInstoreStatBo;
import com.mt.api.modules.domain.bo.InstoreStatPageBo;
import com.mt.api.modules.domain.dto.InstoreDto;
import com.mt.api.modules.domain.dto.InstoreStatByInstoreNoDto;
import com.mt.api.modules.domain.dto.InstoreStatQtyByCargoDto;
import com.mt.api.modules.manager.IInstoreManager;
import com.mt.api.modules.mapper.InstoreMapper;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: plover
 * @Date: 2022-01-02
 * @Description:
 */
@Component
public class InstoreManagerImpl extends ServiceImpl<InstoreMapper, Instore> implements IInstoreManager {

    @Override
    public Page<InstoreStatByInstoreNoDto> statByInstoreNo(InstoreStatPageBo bo) {
        Page page = PageFactory.defaultPage(bo);
        page = baseMapper.statByInstoreNo(page, bo);
        return page;
    }

    @Override
    public List<InstoreDto> getListByDate(AppInstoreStatBo instoreStatBo) {
        return baseMapper.getListByDate(instoreStatBo);
    }

    @Override
    public List<Instore> getInstoreByDate(Integer type, String date) {
        QueryWrapper<Instore> wrapper = Wrappers.query();
        wrapper.eq("Date(instore_time)", date)
                .eq("type", type);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public Instore getInstoreByInstoreNo(String instoreNo) {
        LambdaQueryWrapper<Instore> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Instore::getInstoreNo, instoreNo)
                .last("limit 1");
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<InstoreStatQtyByCargoDto> statQtyByCargo(List<Integer> cargoIdList) {
        return baseMapper.statQtyByCargo(cargoIdList);
    }

}
